*This file creates the main tables in the paper
*******************************************************************************************
* Table 1: Terms of Subsidy Deals 
*******************************************************************************************
******* Industry names
 import delimited using "$datadir/raw/naics4d_labels.csv", clear
 rename naics4d naics4
 tempfile indnames4
 save `indnames4'
 
 
******* Subsidy Data
	u $datadir/subsidy_data, clear
	keep sub_M jobs_total invest_M n_bid id naics3 naics4
	duplicates drop 
	g n=1
	g sub_p50=sub_M
	g jobs_p50 = jobs_total
	g invest_p50 = invest_M
	g n_bid_p50 = n_bid

	tempfile main
	sa `main'

	u `main', clear
	collapse (sum) n (mean) sub_M jobs_total invest_M n_bid (p50) sub_p50 jobs_p50 invest_p50 n_bid_p50
	
	g cost_job = sub_M*1000/jobs_total
	g cost_job_p50 = sub_p50*1000/jobs_p50
		 
	g indgroup = "Full sample" 
	tempfile mean
	save `mean'
	 
	****** Descriptive statistics at 2-digit NAICS level
	u `main', clear

	g indgroup="Mining, Utilities (21-22)" if inrange(naics3, 210, 230)
	replace indgroup="Manufacturing (31-33)" if inrange(naics3, 300, 400)
	replace indgroup="Wholesale, Retail Trade (42-45)" if inrange(naics3, 420, 480)
	replace indgroup="Transport/Warehousing (48-49)" if inrange(naics3, 481, 500)
	replace indgroup="Information Svc. (51)" if inrange(naics3, 510, 520)
	replace indgroup="Finance, Insurance, RE (52-53)" if inrange(naics3, 520, 540)
	replace indgroup="Prof., Scientific, Tech Svc. (54)" if inrange(naics3, 540, 550)
	replace indgroup="Management, Other Svc. (55-81)" if inrange(naics3, 550, 850)

	g order=1 if inrange(naics3, 210, 230)
	replace order=2 if inrange(naics3, 300, 400)
	replace order=3 if inrange(naics3, 420, 480)
	replace order=4 if inrange(naics3, 481, 500)
	replace order=5 if inrange(naics3, 510, 520)
	replace order=6 if inrange(naics3, 520, 540)
	replace order=7 if inrange(naics3, 540, 550)
	replace order=8 if inrange(naics3, 550, 850)

	*By industry (2 digit naics)
	collapse (sum) n (mean) sub_M jobs_total invest_M  n_bid (p50) sub_p50 jobs_p50 invest_p50 n_bid_p50, by(indgroup order)

	g cost_job = sub_M*1000/jobs_total
	g cost_job_p50 = sub_p50*1000/jobs_p50
	
	tempfile ind_n2
	sa `ind_n2'

	****** Add finer breakdown
	u `main', clear
	replace naics4=3251 if inrange(naics4, 3251,3253)

	merge m:1 naics4 using `indnames4', assert(2 3) keep(3) nogen

	replace longname = subinstr(longname, "mfg.", "manuf.", .)
	replace longname = subinstr(longname, "product/parts ", "", .)
	replace longname = subinstr(longname, "Motor vehicle", "Automobile", .)
	replace longname = subinstr(longname, "/medicine", "", .)
	replace longname = subinstr(longname, "/electronic", "", .)
	replace longname = "Information Technology" if longname=="Computer sys design/related svc"
	replace longname = subinstr(longname, "research/development svc", "R\&D", .)
	replace longname = subinstr(longname, "compnt manuf.", "manuf.", .)
	replace longname = subinstr(longname, "products manuf.", "manuf.", .)
	replace longname = "Financial activities" if longname=="Other financial investment actvty"
	
	g indgroup=longname if inlist(naics4, 3251, 3361, 3364, 5239, 5417)

	drop if indgroup==""
	replace indgroup = "\hspace{.75em} \textit{" + indgroup + "} (" + string(naics4) + ")"
	replace indgroup = "\hspace{.75em} \textit{Chemical manuf.} (3251-3)" if naics4==3251

	g order=2.1 if naics4==3251
	replace order=2.2 if naics4==3361
	replace order=2.3 if naics4==3364
	replace order=2.4 if naics4==3364
	replace order=6.1 if naics4==5239
	replace order=7.1 if naics4==5417

	*By industry (3 digit naics)
	collapse (sum) n (mean) sub_M jobs_total invest_M  n_bid (p50) sub_p50 jobs_p50 invest_p50 n_bid_p50, by(indgroup order)

	g cost_job = sub_M*1000/jobs_total
	g cost_job_p50 = sub_p50*1000/jobs_p50
	
	append using `ind_n2'
	sort order

	* append total and average
	append using `mean'

* Make table
	format sub* jobs* cost_job* invest* %12.0fc
	format sub* n_bid %12.1fc

	* MAKE TABLE
	g tab = "\begin{tabular}{l|r|r|rr|rr|rr|rr}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = " &	\# of &  \multicolumn{1}{c|}{ Mean \#} &	\multicolumn{2}{c|}{Subsidy (\\$ \hspace{-1mm}M)}	&	\multicolumn{2}{c|}{Jobs Promised} &	\multicolumn{2}{c|}{Invest (\\$ \hspace{-1mm}M) } & \multicolumn{2}{c}{Cost/Job (\\$ \hspace{-1mm}K) }   \\ " in 1
	g title2 = "Industry (NAICS)	&	Deals &	 \multicolumn{1}{c|}{Bidders} & Mean	&	Med.	&	Mean	&	Med.	 &	Mean	&	Med. &	Mean	&	Med. 	\	\\  " in 1
	g c = " "

*****Output
	local filename = "ind_dstats"

	listtex tab if _n == 1 using "$draftdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex title2 if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)		
	listtex indgroup n  n_bid sub_M sub_p50 jobs_total jobs_p50 invest_M invest_p50 cost_job cost_job_p50 if indgroup!="Full sample" ///
				, appendto("$draftdir/`filename'.tex") rstyle(tabular) 	
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex indgroup n  n_bid  sub_M sub_p50 jobs_total jobs_p50 invest_M invest_p50 cost_job cost_job_p50 if indgroup== "Full sample", appendto("$draftdir/`filename'.tex") rstyle(tabular) 	

	listtex end if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	 
	
********************************************************************************
*Table 2: Reduced Form Evidence: Determinants of Subsidy Size
********************************************************************************
u $datadir/analysis_cz, clear
	
keep *_win sub_M jobs_direct jobs_total year mult_tot invest_B firm naics4 
duplicates drop 
rename *_win *
keep if sub_M<1000

label var corp_tax "\hspace{5mm} Corp. Tax Rate (\%)"
label var income_tax "\hspace{5mm} Income Tax Rate (\%)"
label var invest_B "\hspace{5mm} Investment Planned (\\$ B)"
label var jobs_direct "\hspace{5mm} New Jobs Promised (1,000)"
label var ln_pinc "\hspace{5mm} Log(Income per Capita)"
label var perc_est_n4 "\hspace{5mm} Concentration of Industry Estab."
label var top_RD "\hspace{5mm} Research University"
label var unemp "\hspace{5mm} Unemp. Rate (\%)"
label var r2w "\hspace{5mm} Right-to-Work"
label var airport_any "\hspace{5mm} Airport"
label var wage "\hspace{5mm} Local Industry Wage (\\$1,000)"
label var mult_total "\hspace{5mm} Industry Multiplier"
label var FHFA "\hspace{5mm} House Prices (\\$1,000)"
replace jobs_total=jobs_total/1000

*******************************************Less than 1 billion dollars
eststo clear
* deal variables
eststo: reghdfe sub jobs_direct, absorb(year)
eststo: reghdfe sub jobs_direct invest_B, absorb(year)
eststo: reghdfe sub jobs_direct invest_B mult_total, absorb(year)
*location variables location might care about
eststo: reghdfe sub corp_tax income_tax ln_pinc unemp, absorb(year) 
*location variables firm might care about
eststo: reghdfe sub corp_tax income_tax r2w perc_est_n4 wage top_RD airport_any FHFA, absorb(year)
*all together
eststo: reghdfe sub jobs_direct invest_B  mult_total ///
	corp_tax income_tax ln_pinc unemp ///
	r2w perc_est_n4 wage top_RD airport_any FHFA, absorb(year) 

  esttab using "$draftdir/reg_reducedform.tex", replace ///
		cells(b(fmt(%-10.2fc) star) se(par fmt(%-10.2fc)))	///
		drop(_cons) stats(N r2, fmt(0 2)	///
		labels("Observations" "R-squared"))	///
		order(jobs_direct invest_B  mult_total ///
		corp_tax income_tax r2w ///
		unemp ln_pinc perc_est_n4 ///
		wage FHFA top_RD airport_any) ///
		label  collabels(none) mlabels(none) ///
		refcat(jobs_direct "\textit{Deal Characteristics:}" ///
		corp_tax "\textit{State Characteristics:}" ///
		unemp "\textit{Local Characteristics:}" , nolabel)  ///
		mgroups("Dependent variable: Subsidy (\\$ \hspace{-1mm}M)",	///		// These are multicolumn labels
		pattern(1 0 0 0 0 0 0)								///		
		prefix(\multicolumn{@span}{c}{) suffix(}) span	erepeat(\cmidrule(lr){@span})) 
		
		
********************************************************************************
* Table 3: Manufacturing Parameters
********************************************************************************
insheet using $datadir/mle_coef_manuf.csv, comma clear 

format estimate stderror %12.2fc 

g label = "$\Delta$ Corporate Tax (\%)" if v1=="diff_corp_tax"
g order = 1 if v1=="diff_corp_tax"
replace label ="\hspace{4mm} $\times$ Investment Planned (\\$ B)" if v1=="diff_corp_tax:invest_B"
replace order = 2  if v1=="diff_corp_tax:invest_B"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_corp_tax"
replace order = 3 if v1=="sigma_diff_corp_tax"

replace label = "$\Delta$ Income Tax (\%)" if v1=="diff_income_tax"
replace order = 5 if v1=="diff_income_tax"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_income_tax"
replace order = 6 if v1=="sigma_diff_income_tax"

replace label ="$\Delta$ Property Tax (\%)" if v1=="diff_proptax"
replace order = 7 if v1=="diff_proptax"

replace label  ="$\Delta$ Industry Wage (\\$1,000)" if v1=="diff_wage"
replace order = 8  if v1=="diff_wage"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_wage" 
replace order = 9 if v1=="sigma_diff_wage" 

replace label = "$\Delta$ Electricity Price (c/KwH) $\times$ Investment Planned (\\$ B)" if v1=="invest_B:diff_e_ind" 
replace order = 10 if v1=="invest_B:diff_e_ind" 
replace label = "$\Delta$ Industrial Land Supply $\times$ Investment Planned (\\$ B)" if v1=="invest_B:diff_indus_zoning" 
replace order = 11 if v1=="invest_B:diff_indus_zoning" 
replace label = "$\Delta$ Auto Network Density $\times$ Traditional Manufacturing " if v1=="manuf_type_3:diff_auto_roadnetwork"
replace order = 12 if v1=="manuf_type_3:diff_auto_roadnetwork"

replace label = "$\Delta$ Population with BA+ (\%) $\times$ High-Tech Manufacturing" if v1=="diff_pr_college:manuf_type_1"
replace label =  "$\Delta$ Population with BA+ (\%) $\times$ Traditional Manufacturing" if v1=="diff_pr_college:manuf_type_3"
replace order = 13 if v1=="diff_pr_college:manuf_type_1"
replace order = 14 if v1=="diff_pr_college:manuf_type_3"

replace label = "$\Delta$ Population in Relevant Occupations (1,000)" if v1=="diff_occ_top2_naics3" 
replace label =  "\hspace{4mm} $\times$ Jobs Promised (1,000)"  if v1=="diff_occ_top2_naics3:jobs_direct" 
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_occ_top2_naics3"
replace order = 15 if v1=="diff_occ_top2_naics3" 
replace order = 16 if v1=="diff_occ_top2_naics3:jobs_direct" 
replace order = 17  if v1=="sigma_diff_occ_top2_naics3"

replace label ="$\Delta$ Industry Estab. Share (\%) $\times$ High-Tech Manufacturing " if v1=="manuf_type_1:diff_perc_est_n4"
replace order = 18 if v1=="manuf_type_1:diff_perc_est_n4"

replace label = "Jobs Promised (1,000)" if v1=="jobs_direct"
replace label = "Investment Planned (\\$ B)" if v1=="invest_B"
replace label = "Indirect Jobs (Jobs $\times$ Multiplier)" if v1=="mult_jobs"
replace label = "Corporate Tax (\%)" if v1=="corp_tax"
replace label = "Income Tax (\%)" if v1=="income_tax"
replace label = "Term Limit"  if v1=="term_limit"
replace label = "Log(Income per capita)" if v1=="ln_pinc"
replace label = "Relevant Occupation Wage (\\$1,000)" if v1=="incwage_top_5"
replace label = "Relevant Occupation Wage $\times$ Log(Income per capita)" if v1=="incwage_top_5:ln_pinc"
replace label = "Unemployment (\%)" if v1=="unemp"
replace label = "Unemployment $\times$ Jobs Promised" if v1=="jobs_direct:unemp"

replace order = 19 if v1=="jobs_direct"
replace order = 20 if v1=="invest_B"
replace order = 21 if v1=="mult_jobs"
replace order = 22 if v1=="corp_tax"
replace order = 23 if v1=="income_tax"
replace order = 24 if v1=="term_limit"
replace order = 25 if v1=="ln_pinc"
replace order = 26 if v1=="incwage_top_5"
replace order = 27 if v1=="incwage_top_5:ln_pinc"
replace order = 28 if v1=="unemp"
replace order = 29 if v1=="jobs_direct:unemp"

replace order = 30 if v1=="sigma" 
replace label = "$\sigma$" if v1=="sigma"

sort order 
g pi = (order<=18)

	* MAKE TABLE
	g tab = "\begin{tabular}{lrr}" in 1
	g top = "\toprule" in 1
	g hline = " \hline" in 1 
	g bot = "\bottomrule" in 1
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = "Variable & Estimate & Std. Error \\ " in 1
	g profits= "\textit{Profits:} &&	\\  " in 1
	g valuation= "\textit{Valuation:} &&	\\  " in 1
	g c = " "

*****Output
	local filename = "mle_manuf_results"

	listtex tab if _n == 1 using "$draftdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex profits if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex label estimate stderror if pi==1 ///
				, appendto("$draftdir/`filename'.tex") rstyle(tabular) 
	listtex valuation if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex label estimate stderror if pi==0 ///
				, appendto("$draftdir/`filename'.tex") rstyle(tabular) 
					
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	 

********************************************************************************
* Table 4: Trade/Services Parameters
********************************************************************************
insheet using $datadir/mle_coef_serv.csv, comma clear 

format estimate stderror %12.2fc 

g label = "$\Delta$ Corporate Tax (\%)" if v1=="diff_corp_tax"
g order = 1 if v1=="diff_corp_tax"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_corp_tax"
replace order = 2 if v1=="sigma_diff_corp_tax"

replace label = "$\Delta$ Income Tax (\%)" if v1=="diff_income_tax"
replace order = 3 if v1=="diff_income_tax"
replace label ="\hspace{4mm} $\times$ Jobs Promised (1,000)" if v1=="diff_income_tax:jobs_direct"
replace order = 4 if v1=="diff_income_tax:jobs_direct"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_income_tax"
replace order = 5 if v1=="sigma_diff_income_tax"

replace label ="$\Delta$ Property Tax (\%)" if v1=="diff_proptax"
replace order = 6 if v1=="diff_proptax"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_proptax"
replace order = 7 if v1=="sigma_diff_proptax"

replace label  ="$\Delta$ Right-to-Work State" if v1=="diff_r2w"
replace order = 8  if v1=="diff_r2w"
replace label ="\hspace{4mm} $\times$ Random Effect " if v1=="sigma_diff_r2w" 
replace order = 9 if v1=="sigma_diff_r2w" 

replace label = "$\Delta$ Housing Price (\\$1,000)" if v1=="diff_FHFA"
replace order = 10 if v1=="diff_FHFA"
replace label = "\hspace{4mm} $\times$ Investment Planned (\\$ B)" if v1=="diff_FHFA:invest_B"
replace order = 11 if v1=="diff_FHFA:invest_B"

replace label = "$\Delta$ Industry Wage (\\$1,000) $\times$ High-Skill Services" if v1=="diff_incwage_top_5:lowserv_0"
replace label = "$\Delta$ Industry Wage (\\$1,000) $\times$ Trade/Other Services" if v1=="diff_incwage_top_5:lowserv_1"
replace order = 12 if v1=="diff_incwage_top_5:lowserv_0"
replace order = 13 if v1=="diff_incwage_top_5:lowserv_1"

replace label = "$\Delta$ Commercial Electricity Price (c/KwH)" if v1=="diff_e_comm" 
replace order = 14  if v1=="diff_e_comm" 
replace label = "$\Delta$ Auto Network Density" if v1=="diff_auto_roadnetwork"
replace order = 15 if v1=="diff_auto_roadnetwork"
replace label = "$\Delta$ Large Airport $\times$ Trade" if v1=="diff_airport_any:trade_1"
replace order = 16 if v1=="diff_airport_any:trade_1"

replace label = "$\Delta$ Research University $\times$ Services" if v1=="diff_top_RD:trade_0"
replace label = "$\Delta$ Research University $\times$ Trade" if v1=="trade_1:diff_top_RD"
replace order = 17 if v1=="diff_top_RD:trade_0"
replace order = 18 if v1=="trade_1:diff_top_RD"

replace label = "Jobs Promised (1,000)" if v1=="jobs_direct"
replace label = "Investment Planned (\\$ B)" if v1=="invest_B"
replace label = "Industry Multiplier" if v1=="mult_total"
replace label = "Corporate Tax (\%)" if v1=="corp_tax"
replace label = "Income Tax (\%)" if v1=="income_tax"
replace label = "Sales Tax (\%)" if v1=="sales_tax"
replace label = "Property Tax (\%)" if v1=="proptax"
replace label = "Term Limit"  if v1=="term_limit"
replace label = "Log(Income per capita)" if v1=="ln_pinc"
replace label = "Relevant Occupation Wage (\\$1,000)" if v1=="incwage_top_5"
replace label = "Unemployment (\%)" if v1=="unemp"

replace order = 19 if v1=="jobs_direct"
replace order = 20 if v1=="invest_B"
replace order = 21 if v1=="mult_total"
replace order = 22 if v1=="corp_tax"
replace order = 23 if v1=="income_tax"
replace order = 24 if v1=="sales_tax"
replace order = 25 if v1=="proptax"
replace order = 26 if v1=="term_limit"
replace order = 27 if v1=="ln_pinc"
replace order = 28 if v1=="incwage_top_5"
replace order = 29 if v1=="unemp"

replace order = 30 if v1=="sigma" 
replace label = "$\sigma$" if v1=="sigma"

sort order 
g pi = (order<=18)

	* MAKE TABLE
	g tab = "\begin{tabular}{lrr}" in 1
	g top = "\toprule" in 1
	g hline = " \hline" in 1 
	g bot = "\bottomrule" in 1
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = "Variable & Estimate & Std. Error \\ " in 1
	g profits= "\textit{Profits:} &&	\\  " in 1
	g valuation= "\textit{Valuation:} &&	\\  " in 1
	g c = " "

*****Output
	local filename = "mle_serv_results"

	listtex tab if _n == 1 using "$draftdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex profits if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex label estimate stderror if pi==1 ///
				, appendto("$draftdir/`filename'.tex") rstyle(tabular) 
	listtex valuation if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex label estimate stderror if pi==0 ///
				, appendto("$draftdir/`filename'.tex") rstyle(tabular) 
					
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	 


********************************************************************************
* Table 5: Welfare Analysis 
********************************************************************************
*simulated pi and v in winning places: 
insheet using $datadir/cf_locations.csv, comma clear 
keep if winner==1 
destring sub_m, force replace 
collapse (sum) mean_v mean_pi sub_m share
g type="real"
sa $temp/real_manuf, replace 

insheet using $datadir/cf_locations_serv.csv, comma clear 
keep if winner==1 
destring sub_m, force replace 
collapse (sum) mean_v mean_pi sub_m share
g type="real"
sa $temp/real_serv, replace 

append using $temp/real_manuf 
collapse (sum) mean_v mean_pi sub_m share, by(type)

replace share = share/377

rename mean_* * 
sa $temp/real, replace 
************************************************************
*simulated pi and v in counterfactual places: 
insheet using $datadir/cf_locations.csv, comma clear 
collapse (sum) adj_v adj_pi 
g type="cf"
sa $temp/cf_manuf, replace 

insheet using $datadir/cf_locations_serv.csv, comma clear 
collapse (sum) adj_v adj_pi 
g type="cf"
sa $temp/cf_serv, replace 

append using $temp/cf_manuf 
collapse (sum) adj_v adj_pi, by(type)
sa $temp/cf, replace 

rename adj_* *

append using $temp/real 

replace pi = pi/1000
replace v = v/1000
replace sub = sub/1000

g policy =  "Subsidy Ban" if type=="cf"
replace policy = "Competition" if type == "real"
drop type 
recode sub_ (.=0)

gsort -policy 
g state_payoff = v - sub
g firm_payoff = pi + sub
g total_welfare = v + pi 
g mover = 100-share

order policy v pi sub_m state_pay firm_payoff total 

set obs  3
foreach v in state_payoff firm_payoff total_welfare {
		replace `v' = 100*(`v'[2] - `v'[1])/(`v'[1]) in 3
}


	format mover v pi sub_m state_payoff firm_payoff total_welfare %12.1fc
	
g line3text = "\multicolumn{5}{r|}{\textit{$\Delta$ welfare from competition:}} "

tostring state_payoff firm_payoff total_welfare mover, force usedisplayformat replace 

foreach v in state_payoff firm_payoff total_welfare {
	replace `v' = `v' + "\%" in 3
}

replace mover = mover + "\%"
replace mover = "\multicolumn{1}{c|}{-}" if policy=="Subsidy Ban"
	
	* MAKE TABLE
	g tab = "\begin{tabular}{c|r|rr|r|rr|r}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

		g title1 = " & &  \multicolumn{2}{c|}{Simulated} & Sub  &  \multicolumn{2}{c|}{Payoffs (\\$ \hspace{-1mm}B)} & \multicolumn{1}{c}{Total} \\ " in 1
		g title2 = "  \multicolumn{1}{c|}{Policy}& \multicolumn{1}{c|}{Movers}& \multicolumn{1}{c}{$ v $ (\\$ \hspace{-1mm}B)}   &  \multicolumn{1}{c|}{$\pi$ (\\$ \hspace{-1mm}B)} & \multicolumn{1}{c|}{(\\$ \hspace{-1mm}B)}  & \multicolumn{1}{c}{States} & \multicolumn{1}{c|}{Firms}  & \multicolumn{1}{c}{Welfare} \\ " in 1

	g c = " "

*****Output
	local filename = "counter_v"

	listtex tab if _n == 1 using "$draftdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)		
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)		 
	listtex policy mover v pi sub_m state_pay firm_payoff total if _n<3, appendto("$draftdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)
		listtex line3text state_pay firm_payoff total if _n==3, appendto("$draftdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)
	listtex end if _n == 1, appendto("$draftdir/`filename'.tex") rstyle(none)	 
	